<?php

namespace App\Models;

use Validator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class System extends Model
{
    //软删除
    use SoftDeletes;
    protected $datas = ['created_at','updated_at','deleted_at'];
    protected $dateFormat = 'U';
    protected $fillable = ['webname','copyright'];

    //保存
    public function system ($data)
    {
        $rule = [
            'webname' => 'bail|required',
            'copyright' => 'required'
        ];

        $msg = [
            'webname.required' => '网站名称不能为空',
            'copyright.required' => '版权信息不能为空'
        ];

        $validator = Validator::make($data,$rule,$msg);
        if ($validator->fails()) {
            return $validator->errors()->first();
        }

        $system = $this->find('1');
        $system->webname = $data['webname'];
        $system->copyright = $data['copyright'];
        $result = $system->save();
        if ($result) {
            return 1;
        } else {
            return "保存失败";
        }
    }
}
